/*
Sader engine framework
(c) Rachel J. Morris
MIT License
www.moosader.com
*/

#include "System.h"

namespace sader
{

System::System()
{
    m_screenWidth = m_screenHeight = -1;
}

void System::Init( const char* title, int resW, int resH )
{
    m_title = title;
    m_screenWidth = resW;
    m_screenHeight = resH;
    Init();
}

void System::Init()
{
    if ( m_screenWidth == -1 )
    {
        m_screenWidth = 1024;
        m_screenHeight = 768;
    }
    std::cout<<m_title<<std::endl;
    std::cout<<m_screenWidth<<" x "<<m_screenHeight<<std::endl;
    m_bpp = 32;
    m_fullscreen = false;
    app.settings.DepthBits = 24;
    app.settings.StencilBits = 8;
    app.settings.AntialiasingLevel = 2;

    app.window.Create( sf::VideoMode( m_screenWidth, m_screenHeight, m_bpp ),
                      m_title.c_str(), sf::Style::Close, app.settings );
    app.window.SetFramerateLimit(60);

    // Color/Depth
    glClearDepth( 1.0f );
    glClearColor( 0.5f, 0.1f, 0.1f, 0.5f );

    // Z-buffer read/write
    glEnable( GL_DEPTH_TEST );
    glDepthMask( GL_TRUE );
    glAlphaFunc(GL_GREATER, 0.5f);
    glEnable(GL_ALPHA_TEST);

    // Perspective projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 90.0f, 1.0f, 1.0f, 1500.0f );
}

void System::GetEvent()
{
    sf::Event event;
    app.window.GetEvent( event );

    if ( event.Type == sf::Event::Closed )
    {
        app.window.Close();
    }
}

/**
* Returns program m_status, such as 0 = ITSALLGOOD for no errors.
* @return   ProgramStatus   Returns an enumerated value for the state of the program.
*/
ProgramStatus System::GetStatus()
{
  return m_status;
}

}

